﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace JustinAngel.UnitedNationsNews.CustomControls
{
    public class AnimatedListBox : ListBox
    {
        public AnimatedListBox()
        {
            this.SelectionChanged += new SelectionChangedEventHandler(AnimatedListBox_SelectionChanged);
        }

        void AnimatedListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                var selectedItem = e.AddedItems[0];
                var selectedContainerToAnimateOutandIn = (ListBoxItem) ItemContainerGenerator.ContainerFromItem(selectedItem);

                List<ListBoxItem> listboxItemsToFadeOut = new List<ListBoxItem>();
                foreach (var item in Items)
                {
                    var container = ItemContainerGenerator.ContainerFromItem(item);
                    if (container != null && container != selectedContainerToAnimateOutandIn)
                    {
                        listboxItemsToFadeOut.Add((ListBoxItem) container);
                    }
                }

                //FlyItemOut(selectedContainerToAnimateOutandIn);

            }
        }

        //private void FlyItemOut(ListBoxItem selectedContainerToAnimateOutandIn)
        //{
        //    selectedContainerToAnimateOutandIn.RenderTransform = new TranslateTransform();

        //    Storyboard sb = new Storyboard();
        //    Storyboard.SetTarget(sb, selectedContainerToAnimateOutandIn);

        //    DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
        //    Storyboard.SetTargetProperty(da, );
        //    da.KeyFrames.Add(new EasingDoubleKeyFrame() { Value KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(300)) });
        //}
    }
}
